import Vue from 'vue';
import Vuex from 'vuex';

/**
 * [exportStores store合并后的数组]
 * @type {Array}
 * [lists 表示vuex的属性值集合]
 * @type {Object}
 */
import index from './index';
import admin from './admin';

const exportStores = new Array();
exportStores.push(index, admin);
const lists = {};
lists.state = {};
lists.getters = {};
lists.mutations = {};
lists.actions = {};
const storeAttrArrays = ['state', 'getters', 'mutations', 'actions'];

exportStores.forEach((exportStore, index) => {
	//方法一
	for (let i in exportStore) {
		storeAttrArrays.forEach((value) => {
			if (i == value) {
				var states = exportStore[i];
				for (let j in states) {
					lists[i][j] = states[j];
				}
			}
		})
	}

	//方法二
	// for (let i in exportStore) {
	// 	// console.log(exportStore[i]) //八条数据【对象】
	// 	if (i == 'state') {
	// 		var states = exportStore[i];
	// 		console.log(states); //只根据i显示两条数据
	// 		for (let j in states) {
	// 			lists.state[j] = states[j];
	// 		}
	// 	} else if (i == 'getters') {
	// 		var states = exportStore[i];
	// 		for (let j in states) {
	// 			lists.getters[j] = states[j];
	// 		}
	// 	} else if (i == 'mutations') {
	// 		var states = exportStore[i];
	// 		for (let j in states) {
	// 			lists.mutations[j] = states[j];
	// 		}
	// 	} else if (i == 'actions') {
	// 		var states = exportStore[i];
	// 		for (let j in states) {
	// 			lists.actions[j] = states[j];
	// 		}
	// 	}
	// }

});
// console.log(lists); //输出lists

Vue.use(Vuex);

const store = new Vuex.Store({
	//vuex使用严格模式
	strict: true,
	//vuex属性值
	state: lists.state,
	getters: lists.getters,
	mutations: lists.mutations,
	actions: lists.actions
});
export default store;